<?php

class BlockMethod_GetHttp
    extends BlockMethod {

	protected function getDefaultParams() {

		return
			array(
				"maxredirects" => Value::create("number", 0),
				"timeout"      => Value::create("number", 10),
				"httpversion"  => Value::create("string", "1.1")
				);

	}

	public function run() {

		try {

			$oClient = new Zend_Http_Client(
				$this->getParamByName("uri")->get(),
				array(
					"httpversion"  => $this->getParamByName("httpversion")->get(),
					"maxredirects" => $this->getParamByName("maxredirects")->get(),
					"timeout"      => $this->getParamByName("timeout")->get()
					)
				);

			$oResponse = $oClient->request();

			$oXmlHelper = new XMLHelper();
			$oDocument = $oXmlHelper->createDocumentFromString($oResponse->getBody());

			return "<response status=\"" . $oResponse->getStatus() . "\">" . $oDocument->saveXML($oDocument->documentElement) . "</response>";

		}
		catch(Zend_Exception $oException) {
			throw new Exception_CommonXmlSerializable("http-error", $oException->getMessage());
		}

	}

}

?>